package com.island.service.user;

import com.island.mapper.user.UserMapper;
import com.island.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;

    public User login(String userCode, String userPassword) {
        User user = userMapper.getLoginUserInfo(userCode);
        return user.getUserPassword().equals(userPassword)?user:null;
    }


    public int updatePwd(String newPwd, int id) {
        return userMapper.updatePwd(newPwd,id);
    }

    public int getUserCount(String userName, int userRole) {
        return userMapper.getUserCount(userName,userRole);
    }

    public List<User> getUserList(String userName, int userRole, int currentPageNo, int pageSize) {
        System.err.println("service层接收到的currentPageNo和pageSize = "+currentPageNo+"---"+pageSize);
        return userMapper.getUserList(userName,userRole,currentPageNo,pageSize);
    }

    public static void main(String[] args) {
        System.out.println(new UserServiceImpl().getUserCount("李", 1));
    }

    public int updateUserById(Map map) {
        return userMapper.updateUserById(map);
    }

    public int addUser(Map map) {
        return userMapper.addUser(map);
    }

    public int deleteUserById(int id) {
        return userMapper.deleteUserById(id);
    }

    public User queryUserById(int id) {
        return userMapper.queryUserById(id);
    }

    public User queryUserByUserCode(String userCode) {
        return userMapper.getLoginUserInfo(userCode);
    }
}
